package com.hrms.domain;

import java.text.ParseException;
import java.util.Date;
import java.util.Map;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.hrms.core.Utils;

@PersistenceCapable(detachable="true")
public class Post extends BusinessObjectImpl {
	public static final String TYPE = Post.class.getSimpleName();
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	@Persistent
	private String initials;
	
	@Persistent
	private String userId;
	
	@Persistent
	private String msg;
	
	@Persistent//Posted Date
	private Date date;
	

	public Post() {
		super();
	}

	public Post(Map<String, String[]> parameterMap, String prefix)
			throws IllegalArgumentException, IllegalAccessException,
			ParseException {
		super(parameterMap, prefix);
	}

	public Post(Map<String, String[]> parameterMap)
			throws IllegalArgumentException, IllegalAccessException,
			ParseException {
		super(parameterMap);
	}

	@Override
	public void jdoPreStore()  {
		if(getDate() == null){
			setDate(new Date());
		}
		setUserId(userId.toLowerCase());
		setInitials(initials.toUpperCase());
		setMsg(Utils.cleanedContent(msg));
	}

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public String getInitials() {
		return initials;
	}

	public void setInitials(String initials) {
		this.initials = initials;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	
}
